package com.cloudptt.api.product.func.call.single;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.comm.CommDlg;
import com.cloudptt.api.pjsip.api.SipCallSession;
import com.cloudptt.api.product.func.IFunc;
import com.cloudptt.api.product.func.addr.IAddrOp;
import com.cloudptt.api.product.func.call.CallAttr;
import com.cloudptt.api.product.func.call.CallConst;
import com.cloudptt.api.product.func.call.CallListener;
import com.cloudptt.api.product.func.call.ICallHistory;
import com.cloudptt.api.product.func.call.ICallMute;
import com.cloudptt.api.product.func.call.group.fsm.call.GroupCallAgent;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.api.product.operator.CallOperator;
import com.cloudptt.api.product.parser.ErrParser;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.config.model.ServerInfo;
import com.mcptt.db.model.AddrInfo;
//import com.cloudptt.api.product.func.call.group.GroupCallFunc;

import android.content.Context;

import org.pjsip.pjsua2.pjsip_inv_state;



public class SingleCallTracker implements IFunc,IClearCall
{
	public final static String THIS_FILE = "SingleCallTracker";
	private final static int MAX__CALL_NUM = 1;

	private Context ctx = null;
	private McIdInfo mcIdInfo = null;
	private CallOperator operator = null;
	private ICallMute callMute = null;
//	private ICallNoSnd noSnd = null;
	private IAddrOp addrOp = null;
	private ICallHistory callHistory = null;

	private Class<?> cls = null;
	private Object callMutex = new Object();
	private SingleCallBroadcast broadcast = null;
//	private PeerConnectionClient peerConnectionClient = null;
	private Map<String,SingleCallAgent> callMap = new ConcurrentHashMap<String,SingleCallAgent>();

	public SingleCallTracker(Context ctx,McIdInfo mcIdInfo,IAddrOp addOp,CallOperator operator,ICallMute callMute)
	{
		this.ctx = ctx;
		this.mcIdInfo = mcIdInfo;
		this.addrOp = addOp;
		this.operator = operator;
		this.callMute = callMute;
//		this.noSnd = noSnd;
		this.broadcast = new SingleCallBroadcast(ctx,this);
	}


	public int newCall(CallAttr callAttr)
	{
		Log.d(THIS_FILE, "newCall  callMap.size() = " + callMap.size());
		if(callMap.size() >= MAX__CALL_NUM)
		{
			Set<String> key = callMap.keySet();
			for(Iterator<String> itor = key.iterator();itor.hasNext();)
			{
				String keyStr = itor.next();
				Log.d(THIS_FILE, "newCall  keyStr = " + keyStr);
				SingleCallAgent callAgent = callMap.get(keyStr);
				if(callAgent != null)
				{
					int state = callAgent.getState();
					Log.d(THIS_FILE, "newCall  state = " + state);
					if(state == CallConst.CallState_Activite)
					{
						return CauseCont.OperateCheck_Call_CallTooMany;
					}
					else
					{
						callAgent.destory();
						callMap.remove(callAgent);
					}
				}
			}
		}
		Log.d(THIS_FILE, "newCall  callAttr = " + callAttr);
		SingleCallAgent callAgent = new SingleCallAgent(ctx, callAttr, mcIdInfo, operator,this);
		if(cls == null)
		{
			Log.d(THIS_FILE, "newCall  cls = null");
		}
		callAgent.setPrivacyClass(cls);
		String callKey = callAttr.getCallKey();
		Log.d(THIS_FILE, "newCall  callKey = " + callKey);
		callMap.put(callKey, callAgent);
//		setSnd();
		return CauseCont.OperateCheck_Suc;
	}

	public int doUserAction(String callKey,int userAction)
	{
		Log.d(THIS_FILE, "doUserAction userAction = " + CallConst.userActionTag(userAction));
		int result = CauseCont.OperateErr_NoAgent;
		SingleCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
//			if(userAction == CallConst.BtnAction_Hangup)
//			{
//				setSnd();
//			}
			if(userAction == CallConst.BtnAction_Accept)
			{
				callMute.muteCall(true);
			}
			
			result = callAgent.doUserAction(userAction);
			Log.d(THIS_FILE, "doUserAction result = " + result);

			if(userAction == CallConst.BtnAction_Make
					&& CauseCont.OperateCheck_Suc != result)
			{
				this.clearAllCallAgent();
			}

			return result;
		}
		return result;
	}
	public boolean isHasCall(String callKey)
	{
		Log.d(THIS_FILE, "isHasCall callKey = " + callKey);
		if(callKey != null
				&& this.getCallAgent(callKey) != null)
		{
			return true;
		}
		return false;
	}

	//	public void clearCall(String callKey)
	//	{
	//		Log.d(THIS_FILE, "clearCall callKey = " + callKey);
	//		if(callKey != null
	//				&& callMap != null)
	//		{
	//			WebRtcCallAgent callAgent = callMap.remove(callKey);
	//			Log.d(THIS_FILE, "clearCall callAgent = " + callAgent);
	//			callAgent.destory();
	//			callAgent = null;
	//		}
	//	}

	//	@Override
	//	public void receiveCallAction(int callId,int talkAction) {
	//		// TODO Auto-generated method stub
	//		Log.d(THIS_FILE, "receiveCallAction talkAction = " + talkAction);
	//		if(curCallAgent != null)
	//		{
	//			curCallAgent.receiveCallAction(callId,talkAction);
	//			if(GroupCallConst.Session_Disconnected == talkAction)
	//			{
	//				curCallAgent.doExit();
	//				curCallAgent = null;
	//				//				callMap.clear();
	//			}
	//		}
	//
	//	}

	public void incomingCall(SipCallSession callSession)
	{
		if(callSession == null)
		{
			return;
		}
		Log.d(THIS_FILE, "incomingCall callSession = " + callSession);

		String imcomingNum = callSession.getRemoteContact();
		int callType = callSession.getCallType();

		if(callType != CallAttr.CallType_Single
				&& callType != CallAttr.CallType_Video_Push
				&& callType != CallAttr.CallType_Video_Pull
				
				&& callType != CallAttr.CallType_Video_Trans
				&& callType != CallAttr.CallType_Video_TransGrp
				&& callType != CallAttr.CallType_Video_PushGrp)
		{
			return;
		}
		AddrInfo imcomingInfo = addrOp.getUserInfoByNum(imcomingNum);
		
		String callIdStr = callSession.getCallIdStr();
		if(callMap.size() > 0)
		{
			Log.d(THIS_FILE, "incomingCall callMap.size() > 0");
			operator.hangupCall(callIdStr,486);
			return;
		}

		if(operator != null)
		{
			operator.ring(true);
		}

		CallAttr callAttr = new CallAttr(callType,imcomingInfo,CallAttr.CallDir_MT,callSession.isUseVideo());
		callAttr.updateCallIdStr(callIdStr);
		int result = newCall(callAttr);
		Log.d(THIS_FILE, "incomingCall result = " + result);

		SingleCallAgent callAgent = this.getCallAgent(imcomingNum);
		if(callAgent == null)
		{
			Log.d(THIS_FILE, "incomingCall callAgent == null");
			operator.hangupCall(callIdStr,486);
			return;
		}
		
		
		callAgent.updateCallId(callIdStr);
		int callState = callAgent.getState();
		Log.d(THIS_FILE, "incomingCall callIdStr = " + callIdStr + " talkState = " + callState);
		if(CallConst.CallState_InitState == callState
				&& result == CauseCont.OperateCheck_Suc)
		{
			if(callType == CallAttr.CallType_Video_Push
					|| callType == CallAttr.CallType_Video_Pull
					
					|| callType == CallAttr.CallType_Video_Trans
					|| callType == CallAttr.CallType_Video_TransGrp
					|| callType == CallAttr.CallType_Video_PushGrp)
			{
				callAgent.doAcceptAction();
			}
			callAgent.receiveCallAction(CallConst.Session_Connecting);
		}
		else
		{
			result = operator.hangupCall(callIdStr,486);
			if(result != CauseCont.OperateCheck_Suc) 
			{
				String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
				CommDlg.showToast(ctx,errStr);
				return;
			}
		}
		

		//		if(curCallAgent != null)
		//		{
		//			curCallAgent.incomingCall(imcomingInfo);
		//		}
	}

	public void recvPCallSession(SipCallSession callSession)
	{
		Log.d(THIS_FILE, "recvPCallSession into ");
		synchronized (callMutex) 
		{
			Log.d(THIS_FILE, "recvPCallSession callSession is " + callSession.toString());
			//			int incommingCallstate = callSession.getCallState();
			String callIdStr = callSession.getCallIdStr();
			String key = callSession.getRemoteContact();
			Log.d(THIS_FILE, "recvPCallSession key = " + key);
			SingleCallAgent callAgent = this.getCallAgent(key);
			if(callAgent == null)
			{
				Log.d(THIS_FILE, "recvPCallSession callAgent == null");
				operator.hangupCall(callIdStr,486);
				return;
			}
			callAgent.updateCallId(callIdStr);
			int state = callSession.getCallState();
//			if(InvState.EARLY == state
//					|| InvState.CONFIRMED == state)
//			{
//				callAgent.sendLocalCandidateByMo();
//			}
			if(pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED == state)
			{
				int lastCode = callSession.getLastStatusCode();
				Log.d(THIS_FILE, "recvPCallSession lastCode is " + lastCode +" remote  "+callSession.getRemoteContact());
				if(SipCallSession.StatusCode.OK == lastCode)
				{
					if(callAgent != null)
					{
						boolean hasVideo = true;
						Log.d(THIS_FILE, "recvPCallSession cachedVideo="+callSession.mediaHasVideo() );
						if (callSession.mediaHasVideo()) {
							hasVideo = true;
						}else {
							hasVideo = false;
						}
						Log.d(THIS_FILE, "recvPCallSession hasVideo =" + hasVideo );
						//int mediaStatus = callSession.getMediaStatus();
						/*int callType = callSession.getCallType();
						if(callType == CallAttr.CallType_Video_Push
								|| callType == CallAttr.CallType_Video_Pull

								|| callType == CallAttr.CallType_Video_Trans
								|| callType == CallAttr.CallType_Video_TransGrp
								|| callType == CallAttr.CallType_Video_PushGrp)
						{
							callAgent.onDisplayVideo(callId);
						}
						else if(hasVideo
								&& callType == CallAttr.CallType_Single)*/
//						if(hasVideo)
//						{
//							int callState = callAgent.getState();
//							Log.d(THIS_FILE, "recvPCallSession callState =" + callState );
//							boolean isActivite = (callState == CallConst.CallState_Activite);
//							callAgent.onDisplayVideo(callId,!isActivite);
//						}
						callAgent.setHaseVideo(hasVideo);
						callAgent.receiveCallAction(CallConst.Session_Confirmed_Active);
					}
					
				}
				else
				{
					int callDir = callAgent.getCallAttr().getCallDir();
					int code = callSession.getLastStatusCode();
					showErrToast(callDir,code,ErrParser.Type_FloorResp);
				}

//				CallAttr callAttr = callAgent.getCallAttr();
//				int callType = callAttr.getCallType();
//				if(CallAttr.CallType_Single == callType)
//				{
//					setNoSnd();
//				}
			}
			else if(pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED == state)
			{
				//					curCallSession = null;
				callAgent.receiveCallAction(CallConst.Session_Disconnected);
				Log.d(THIS_FILE, "recvPCallSession DISCONNECTED callAgent.getState() = " + callAgent.getState());
				int callDir = callAgent.getCallAttr().getCallDir();
				int code = callSession.getLastStatusCode();
				showErrToast(callDir,code,ErrParser.Type_CallResp);

//				CallAttr callAttr = callAgent.getCallAttr();
//				AddrInfo receiver = callAttr.getCalled();
//				AddrInfo sender = callAttr.getCallLogAddrInfo(mcIdInfo);
//				String secStr = callAgent.getTimeDesc();
//				newCallHistory(receiver,sender,callDir,code,secStr);

				clearAllCallAgent();
				
				
				callMute.muteCall(false);
//				setNoSnd();
//				int callType = callAttr.getCallType();
//				if(CallAttr.CallType_Single == callType)
//				{
//					//setSnd();
//				}
			}
		}
	}

	public void receivePCallMediaStatus(String callKey,int mediaStatus)
	{
		Log.d(THIS_FILE, "receivePCallMediaStatus callKey = " + callKey +" mediaStatus = " + mediaStatus);
		SingleCallAgent callAgent = getCallAgent(callKey);
		if (callAgent == null) {
			Log.d(THIS_FILE, "receivePCallSession callAgent == null");
			return;
		}
		callAgent.receivePCallMediaStatus(mediaStatus);
	}
//	private void newCallHistory(AddrInfo receiver,AddrInfo sender,int callDir,int code,String secStr)
//	{
//		boolean isAdd = false;
//		StringBuffer contentStr = new StringBuffer();
//		if(secStr != null)
//		{
//			String str = Resource.getString("e_log_suc");
//			contentStr.append(str).append(secStr);
//		}
//		else
//		{
//			if(code == 403
//					|| code == 408
//					|| code == 486
//					|| code == 487
//					|| code == 603)
//			{
//				ErrInfo errInfo = new ErrInfo(CauseCont.ERROR_TITLE_LOG, code);
//				if( errInfo != null )
//				{
//					String str = errInfo.getErrDesc();
//					contentStr.append(str);
//				}
//			}
//			else
//			{
//				String str = Resource.getString("e_log_err");
//				contentStr.append(str + code);
//			}
//
//
//			if(code == 408
//					|| code == 487)
//			{
//				isAdd = true;
//			}
//		}
//		int dir = SessionInfo.Direction_Type_Send;
//		if(callDir == CallAttr.CallDir_MT)
//		{
//			dir = SessionInfo.Direction_Type_Receive;
//		}
//		callHistory.newCallHistory(receiver, sender,dir,isAdd,contentStr.toString());	
//	}

	private void showErrToast(int callDir,int code,int type)
	{
		Log.d(THIS_FILE, "showErrToast callDir = " + callDir + " code = " + code + " type = " + type);
		ErrParser errParser = new ErrParser(code, type, ctx);
		if(errParser.isErr() )
		{
			if(code == 486
					&& callDir == CallAttr.CallDir_MT)
			{
				return;
			}

			String errStr = errParser.getErrStr();
			if(errStr != null
					&& !errStr.equals(""))
			{
				CommDlg.showToast(ctx, errStr);
			}
		}
	}

	public String getCallDesc()
	{
		int pcallSize = 0;
		int otherCallSize = 0;
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.get(key);
			CallAttr attr = agent.getCallAttr();
			if(attr != null
					&& attr.getCallType() == CallAttr.CallType_Single)
			{
				pcallSize ++;
			}
			else 
			{
				otherCallSize ++;
			}
		}
		return "" + otherCallSize + pcallSize;
	}

	private SingleCallAgent getCallAgent(String key)
	{
		Log.d(THIS_FILE, "getCallAgent  key = " + key);
		Log.d(THIS_FILE, "getCallAgent  callMap = " + callMap);
		if(callMap == null
				|| callMap.size() <=0)
		{
			return null;
		}
		
		return callMap.get(key);
	}

//	private PCallAgent getTestCallAgent()
//	{
//		Log.d(THIS_FILE, "getTestCallAgent");
//		Set set = callMap.keySet();
//		String key = set.iterator().next().toString();	
//		Log.d(THIS_FILE, "getTestCallAgent key = " +key);
//		if(callMap == null
//				|| callMap.size() <=0)
//		{
//			return null;
//		}
//		return callMap.get(key);
//	}

	public boolean isNewCall(int state)
	{
		if(state == pjsip_inv_state.PJSIP_INV_STATE_CALLING
				|| state == pjsip_inv_state.PJSIP_INV_STATE_INCOMING
				|| state == pjsip_inv_state.PJSIP_INV_STATE_CONNECTING)
		{
			return true;
		}
		return false;
	}


	public void setPrivacyClass(Class cls)
	{
		Log.d(THIS_FILE, "setPrivacyClass cls = " + cls);
		this.cls = cls;
	}
	public void setListener(CallListener callListener)
	{
		Log.d(THIS_FILE, "setListener callListener = " + callListener);
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.get(key);
			agent.setListener(callListener);
		}
	}

	//	public void setSurfaceView(String callKey, SurfaceViewRenderer localRender, SurfaceViewRenderer remoteRender) {
	//		// TODO Auto-generated method stub
	//		WebRtcCallAgent callAgent = this.getCallAgent(callKey);
	//		if(callAgent != null)
	//		{
	//			callAgent.setSurfaceView(localRender, remoteRender);
	//		}
	//	}
//	public SurfaceViewRenderer getSurfaceView(String callKey, int type)
//	{
//		SingleCallAgent callAgent = this.getCallAgent(callKey);
//		if(callAgent != null)
//		{
//			return callAgent.getSurfaceView(type);
//		}
//		return null;
//	}
	public void setIslaunch(String callKey, boolean islaunch)
	{
		SingleCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			callAgent.setIslaunch(islaunch);
		}
	}

	//	public GroupCallInfo getCallInfo(String callKey)
	//	{
	//		WebRtcCallAgent callAgent = this.getCallAgent(callKey);
	//		if(callAgent != null)
	//		{
	//			return callAgent.getCallInfo();
	//		}
	//		return null;
	//	}
	//	public List<GroupCallInfo> getTalkInfoList(int callType)
	//	{
	//		List<GroupCallInfo> list = new Vector<GroupCallInfo>();
	//		Set<String> keySet = callMap.keySet();
	//		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
	//		{
	//			String key = itor.next();
	//			WebRtcCallAgent agent = callMap.get(key);
	//			GroupCallInfo info = agent.getCallInfo();
	//			list.add(info);
	//		}
	//		return list;
	//	}

	public void destory() {
		Log.d(THIS_FILE, "destory");
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.get(key);
			agent.destory();
		}
		//		callAttr = null;
	}

	//	@Override
	//	public boolean isActiveCall() {
	//		// TODO Auto-generated method stub
	//		if(curCallAgent != null)
	//		{
	//			return curCallAgent.isActiveCall();
	//		}
	//		return false;
	//	}

	//	@Override
	//	public int getState() {
	//		// TODO Auto-generated method stub
	//		return 0;
	//	}
	@Override
	public void onLanChange(String lanType) {
		// TODO Auto-generated method stub

	}
	@Override
	public void onLogined(McIdInfo mcIdInfo,ServerInfo info,boolean isLoginSuc)
	{}
	@Override
	public void doNetworkChange(boolean isConn)
	{
		Log.d(THIS_FILE, "doNetworkChange isConn = " + isConn);
		if(!isConn)
		{
			clearAllCallAgent();
		}
	}
	@Override
	public void doForceDetach()
	{
		Log.d(THIS_FILE, "doForceDetach");
		clearAllCallAgent();
	}
	@Override
	public void doLogout()
	{
		Log.d(THIS_FILE, "doLogout");
		clearAllCallAgent();
	}
	@Override
	public void doExit()
	{
		Log.d(THIS_FILE, "doExit");
		clearAllCallAgent();
		this.broadcast.clearResource();
		broadcast = null;
	}

	//	public CallOperator getOperator() {
	//		return operator;
	//	}

	//	public CallAgent getCallAgent() {
	//		return curCallAgent;
	//	}

	public String toString() 
	{
		StringBuffer strBuff = new StringBuffer("McpttCall:");
		//		strBuff.append("callAttr = ").append(callAttr).append(",");
		//		strBuff.append("callAgent = ").append(callAgent).append(";");

		return strBuff.toString();
	}

	public String getSysInfoStr()
	{
		StringBuffer strBuf = new StringBuffer("SingleCallTracker:");
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.get(key);
			strBuf.append(agent.getSysInfoStr());
		}
		return strBuf.toString();
	}
	@Override
	public void onKeepAlive(boolean isconnected) {
		// TODO Auto-generated method stub
		if(!isconnected)
		{
			clearAllCallAgent();
		}
	}

	public void clearAllCallAgent()
	{
		try
		{
		Log.d(THIS_FILE, "clearAllCallAgent");
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.remove(key);
			agent.destory();
			agent = null;
		}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private void destoryAllCall()
	{
		Log.d(THIS_FILE, "destoryAllCall callMap = " + callMap);
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.remove(key);
			agent.destoryCall();
			agent.destory();
			agent = null;
		}
	}

	public boolean isHaveActivePCall()
	{
		Log.d(THIS_FILE, "isHaveActivePCall");
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.get(key);
			if(agent.isHaveActivePCall())
			{
				return true;
			}
		}
		return false;
	}
	
	public boolean isHaveActivePVoiceCall()
	{
		Log.d(THIS_FILE, "isHaveActivePVoiceCall");
		Set<String> keySet = callMap.keySet();
		for(Iterator<String> itor = keySet.iterator();itor.hasNext();)
		{
			String key = itor.next();
			SingleCallAgent agent = callMap.get(key);
			
			if(agent.isHaveActivePVoiceCall())
			{
				return true;
			}
		}
		return false;
	}
	public boolean isMicMute(String callKey)
	{
		SingleCallAgent callAgent = this.getCallAgent(callKey);
//		if(callAgent != null)
//		{
//			return callAgent.isMicMute();
//		}
		return false;
	}

	public int getWebrtcCallState(String callKey)
	{
		SingleCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			return callAgent.getState();
		}
		return CallConst.CallState_InitState;
	}
	public boolean isActiveCall(String callKey) {
		// TODO Auto-generated method stub
		SingleCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			return callAgent.isActiveCall();
		}
		return false;
	}

	public void setCallHistory(ICallHistory callHistory) {
		this.callHistory = callHistory;
	}
	
	public void screenAngle(String callKey, int angle)
	{
		SingleCallAgent callAgent = this.getCallAgent(callKey);
		if(callAgent != null)
		{
			callAgent.screenAngle(angle);
		}
	}

//	private void setNoSnd()
//	{
//		Log.d(THIS_FILE, "agent setNoSnd");
//		Message msg = mHandler.obtainMessage(MsgId_SetNoSnd);
//		mHandler.sendMessage(msg);
//	}
//
//	private void setSnd()
//	{
//		Log.d(THIS_FILE, "agent setSnd ");
//		Message msg = mHandler.obtainMessage(MsgId_SetSnd);
//		mHandler.sendMessage(msg);
//	}
//	
//	private final static int MsgId_SetNoSnd = 2;
//	private final static int MsgId_SetSnd = 3;
//	private  Handler mHandler = new Handler(){ 
//		@Override
//		public void handleMessage(Message msg)
//		{
//			Log.d(THIS_FILE, "handleMessage msg.what = " + msg.what);
//			if(msg.what == MsgId_SetNoSnd)
//			{
//				try {
//					noSnd.setNoSnd();
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}
//			else if(msg.what == MsgId_SetSnd)
//			{
//				try {
//					noSnd.setSnd(true);
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}
//		}
//	};
}
